//
//  CheckListCell.m
//  New_Runway
//
//  Created by mack on 2018/2/12.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "CheckListCell.h"
#import "HomeWebviewLoadingController.h"
#import "CheckValuationController.h"

@interface CheckListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *carImage;
@property (weak, nonatomic) IBOutlet UILabel *carName;
@property (weak, nonatomic) IBOutlet UILabel *carMileage;
@property (weak, nonatomic) IBOutlet UILabel *carVin;
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UILabel *shopName;
@property (weak, nonatomic) IBOutlet UILabel *checkCompletedBtn;
@property (weak, nonatomic) IBOutlet UIButton *checkVaBtn;
@property (weak, nonatomic) IBOutlet UIButton *checkPriceBtn;
@property (weak, nonatomic) IBOutlet UIImageView *tipsImage;

@end

@implementation CheckListCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setResult:(checkResult *)result{
    _result = result;
    
    self.checkVaBtn.hidden = result.detectionState == 20;
    self.checkPriceBtn.hidden = result.detectionState == 20;
    self.checkCompletedBtn.hidden = result.detectionState != 20;
    self.tipsImage.image = result.detectionState == 20? getImageFromName(@"icon_detected"): getImageFromName(@"icon_wait_detected");
    
    [self.carImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImageApi,result.car.carImageUrl]] placeholderImage:[UIImage imageNamed:@"tu"]];
    self.carName.text = result.car.carTitle;
    NSString *time = [[NRWCarTurnTime timestampSwitchTime:result.car.carLicenceDate andFormatter:@"yyyy-MM"] isEqualToString:@"1900-01"]? @"未上牌": [NRWCarTurnTime timestampSwitchTime:result.car.carLicenceDate andFormatter:@"yyyy-MM"];
    self.carMileage.text = [NSString stringWithFormat:@"%f万公里/%@",result.car.carMileage,time];
    self.carVin.text = result.car.carVin;
    
    self.userName.text = [NSString stringWithFormat:@"%@ %@",result.user.userName,result.user.userMobile];
    self.shopName.text = result.car.shop.shopName;
   

}
-(void)setIndex:(NSIndexPath *)index{
    _index = index;
}
-(void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
}

- (IBAction)checkValuation:(id)sender {
    
    CheckValuationController *checkVC = [[CheckValuationController alloc] init];
    checkResult *result = self.dataArray[_index.row];
    checkVC.carId = result.carId;
    checkVC.detectionId = result.detectionId;
    [self.nav pushViewController:checkVC animated:YES];
}
- (IBAction)queryValuation:(id)sender {
    
    HomeWebviewLoadingController *shopWebVc = [[HomeWebviewLoadingController alloc] init];
    shopWebVc.mainTitle = @"车辆估值";
    shopWebVc.urlstr =@"http://m.che300.com/pinggu";
    [self.nav pushViewController:shopWebVc animated:YES];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
